@extends('app')

@section('content')
<link rel="stylesheet" href="{{asset('/addons/kindeditor/themes/default/default.css')}}" />
<link rel="stylesheet" href="{{asset('/addons/kindeditor/plugins/code/prettify.css')}}" />
<script src="{{asset('/addons/kindeditor/kindeditor.js')}}" type="text/javascript"></script>
<script src="{{asset('/addons/kindeditor/lang/zh_CN.js')}}" type="text/javascript"></script>
<script src="{{asset('/addons/kindeditor/plugins/code/prettify.js')}}" type="text/javascript"></script>
<script type="text/javascript">
<!--
editorInit();
xweidrag();
//-->
</script>
<ul class="nav nav-tabs">
    <li><a href="/admin/teaches/index/course/index/{{$chapterid}}">列表</a></li>
     <li class="active"><a href="#">新增</a></li>
</ul>
<form id="newsForm">
    <div class="content-edit-left" id="content-edit-left">
        <div class="captions">
            <input type="hidden" name="chapterid" value="{{$chapterid}}">
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章标题：</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" class="form-control" name="name" id="name" placeholder="标题" value="@if(!empty($result)){{$result->name}}@endif">
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="description">
            <div class="form-group clearfix">
                <label class="col-sm-3">简介：</label>
            </div>
            <div class="form-group clearfix">
                <div class="col-sm-12 ">
                    <textarea class="form-control content" name="description" placeholder="在这里输入简介" id="description">@if(!empty($result)){!! $result->description['name'] !!}@endif</textarea>
                    <div class="dropzone clearfix" id="desc_img_box">
                        @if(!empty($result))
                        @if(!empty($result->description['img']))
                        @foreach($result->description['img'] as $desimg)
                        @if(!empty($desimg))
                        <div class="drop-item">
                            <img src="{{ $desimg }}"  width="100"/>
                            <a href="javascript:void(0)" class="small-pic-del" onclick="deleteImg(this.parentNode)"><i class="icon-remove"></i></a>
                        </div>
                        @endif
                        @endforeach
                        @endif
                        @else
                        <span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span>
                        @endif
                    </div>
                </div>
            </div>
        </div>
        <div class="tools">
            <div class="form-group clearfix">
                <label class="col-sm-3">工具／原料：</label>
            </div>
            <div id="tools-layout">
                @if(!empty($result))
                @foreach($result->tools as $ke=>$tol)
                <div class="form-group can-del clearfix" @if($ke==0) id="tools-layout" @endif>
                    <div class="col-sm-12 ">
                        <input  type="text" class="form-control" name="tools[]" id="tools_{{$ke}}" value="{{ $tol }}" placeholder="工具/原料">
                        <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                    </div>
                </div>
                @endforeach
                @else
                <div class="form-group can-del clearfix">
                    <div class="col-sm-12 ">
                        <input type="text" class="form-control" name="tools[]" placeholder="工具/原料">
                    </div>
                    <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                </div>
                <div class="form-group can-del clearfix">
                    <div class="col-sm-12 ">
                        <input type="text" class="form-control" name="tools[]" placeholder="工具/原料">
                    </div>
                    <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                </div>
                @endif
            </div>
            <div class="form-group clearfix">
                <div class="col-sm-3">
                    <button type="button" class="btn btn-default btn-block" name="addmoretools" id="addmoretools"><i class="glyphicon glyphicon-plus"></i>添加工具/原料</button>
                </div>
            </div>
        </div>
        <script type="text/javascript">
			function contentTitleEdit(own,id)
			{
				$(own).parent().hide();
				$("#"+id).show();
			}
        </script>
        <div class="content-layout" id="content-layout">
            @if(!empty($result))
            @if(array_key_exists('title',  $result->content[0]))
            @foreach($result->content as $fkey=>$firstcon)
            <div id="content_step_{{$fkey}}">
                <div class="form-group clearfix">
                    <label class="col-sm-3">
                        @if($firstcon['title']) {{ $firstcon['title'] }} @else 方法／步骤 @endif
                        <i class="fa fa-edit fa-fw" onclick="contentTitleEdit(this,'content_title_{{$fkey}}')"></i>
                    </label>
                    <div class="col-sm-3 content_title" id="content_title_{{$fkey}}">
                        <input type="text" class="form-control" name="content_title_{{$fkey}}" value="@if(!empty($firstcon['title'])) {{$firstcon['title']}} @else 方法／步骤 @endif">
                    </div>
                    <a  class="delete-btn" onclick="deleteBigStep(this)"><i class="icon-remove"></i></a>
                </div>
                @foreach($firstcon['content'] as $key=>$con)
                <div class="form-group can-del clearfix">
                    <div class="col-sm-12 ">
                        <textarea class="form-control content" name="content_step_{{$fkey}}_{{$key}}" placeholder="在这里输入方法／步骤">{!! $con['name'] !!}</textarea>
                        <div class="dropzone clearfix" id="content_step_{{$fkey}}_{{$key}}_img_box">
                            @if(!empty($con['img']))
                            @foreach($con['img'] as $conimg)
                            <div class="drop-item">
                                <img src="{{ $conimg }}" width="100"/>
                                <a href="javascript:void(0)" class="small-pic-del" onclick="deleteImg(this.parentNode)"><i class="icon-remove"></i></a>
                            </div>
                            @endforeach
                            @else
                            <span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span>
                            @endif
                        </div>
                    </div>
                    <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                </div>
                @endforeach
            </div>
            <div class="form-group clearfix">
                <div class="col-sm-3">
                    <button type="button" class="btn btn-default btn-block" name="addmorecontent" onclick="addMoreContent('content_step_{{$fkey}}')"><i class="glyphicon glyphicon-plus"></i>添加方法/步骤</button>
                </div>
            </div>
            @endforeach
            @else
            <div id="content_step_1">
                <div class="form-group clearfix">
                    <label class="col-sm-3">
                        方法／步骤
                        <i class="fa fa-edit fa-fw" onclick="contentTitleEdit(this,'content_title')"></i>
                        <a  class="delete-btn" onclick="deleteBigStep(this)"><i class="icon-remove"></i></a>
                    </label>
                    <div class="col-sm-3 content_title" id="content_title">
                        <input type="text" class="form-control" name="content_title_1" value="方法／步骤">
                        <a  class="delete-btn" onclick="deleteBigStep(this)"><i class="icon-remove"></i></a>
                    </div>
                </div>
                @foreach($result->content as $key=>$con)
                <div class="form-group can-del clearfix">
                    <div class="col-sm-12 ">
                        <textarea class="form-control content" name="content_step_1_{{$key}}" placeholder="在这里输入方法／步骤" id="content_{{$key}}">{{ $con['name'] }}</textarea>
                        <div class="dropzone clearfix" id="content_step_1_{{$key}}_img_box">
                            @if(!empty($con['img']))
                            @foreach($con['img'] as $conimg)
                            <div class="drop-item">
                                <img src="{{ $conimg }}" width="100"/>
                                <a href="javascript:void(0)" class="small-pic-del" onclick="deleteImg(this.parentNode)"><i class="icon-remove"></i></a>
                            </div>
                            @endforeach
                            @else
                            <span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span>
                            @endif
                        </div>
                    </div>
                    <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                </div>
                @endforeach
            </div>
            <div class="form-group clearfix">
                <div class="col-sm-3">
                    <button type="button" class="btn btn-default btn-block" name="addmorecontent" id="addmorecontent"><i class="glyphicon glyphicon-plus"></i>添加方法/步骤</button>
                </div>
            </div>
            @endif
            @else
            <div id="content_step_1">
                <div class="form-group clearfix">
                    <label class="col-sm-3">
                        方法／步骤
                        <i class="fa fa-edit fa-fw" onclick="contentTitleEdit(this,'content_title')"></i>
                    </label>
                    <div class="col-sm-3 content_title" id="content_title">
                        <input type="text" class="form-control" name="content_title_1" value="方法／步骤">
                    </div>
                </div>
                <div class="form-group can-del clearfix" >
                    <div class="col-sm-12 ">
                        <textarea class="form-control content" name="content_step_1_1" placeholder="在这里输入方法／步骤"></textarea>
                        <div class="dropzone clearfix" id="content_step_1_1_img_box"><span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span></div>
                    </div>
                    <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                </div>
                <div class="form-group can-del clearfix">
                    <div class="col-sm-12 ">
                        <textarea class="form-control content" name="content_step_1_2" placeholder="在这里输入方法／步骤"></textarea>
                        <div class="dropzone clearfix" id="content_step_1_2_img_box"><span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span></div>
                    </div>
                    <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                </div>
                <div class="form-group can-del clearfix">
                    <div class="col-sm-12 ">
                        <textarea class="form-control content" name="content_step_1_3" placeholder="在这里输入方法／步骤" id="content_3"></textarea>
                        <div class="dropzone clearfix" id="content_step_1_3_img_box"><span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span></div>
                    </div>
                    <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                </div>
            </div>
            <div class="form-group clearfix">
                <div class="col-sm-3">
                    <button type="button" class="btn btn-default btn-block" name="addmorecontent" id="addmorecontent"><i class="glyphicon glyphicon-plus"></i>添加方法/步骤</button>
                </div>
            </div>
            @endif
        </div>
        <div class="content-layout end-layout">
            <div class="form-group clearfix">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-default btn-block" name="addnewcontent" id="addnewcontent"><i class="glyphicon glyphicon-plus"></i>添加新步骤栏目</button>
                </div>
            </div>
            <div class="form-group clearfix">
                <label class="col-sm-3">注意事项</label>
            </div>             
            <div id="notice">
                @if(!empty($result))
                @foreach($result->notice as $keyy=>$notice)
                <div class="form-group can-del clearfix" @if( $keyy ==0 )id="notice" @endif>
                    <div class="col-sm-12 ">
                        <input class="form-control"name="notice[]" placeholder="注意事项" value="{{ $notice }}">
                    </div>
                    <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                </div>
                @endforeach
                @else
                <div class="form-group can-del clearfix">
                    <div class="col-sm-12 ">
                        <input class="form-control" name="notice[]" placeholder="注意事项">
                    </div>
                    <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                </div>
                <div class="form-group can-del clearfix">
                    <div class="col-sm-12">
                        <input class="form-control" name="notice[]" placeholder="注意事项">
                    </div>
                    <a class="delete-btn"  onclick="deleteStep(this)"><i class="icon-remove"></i></a>
                </div>
                @endif
            </div>
            <div class="form-group clearfix">
                <div class="col-sm-3">
                    <button type="button" class="btn btn-default btn-block" name="addmorenotice" id="addmorenotice" >
                        <i class="glyphicon glyphicon-plus"></i>
                        添加注意事项
                    </button> 
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">教程价格：</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="number" name="price" class="form-control" value="@if(!empty($result)){{$result->price?$result->price:0}}@endif">
                    <div class="help-block" >为0则为免费课程。</div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">教程排序：</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="number" name="sort" class="form-control" value="@if(!empty($result)){{$result->sort?$result->sort:0}}@endif">
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章权限：</label>
                <div class="col-sm-9 col-xs-12">
                    <label class="radio-inline">
                    	<input type="radio" name="need_login"  value="1"  @if(!empty($result) && $result->need_login == 1) checked @endif>&nbsp;&nbsp;需要用户登录
                	</label>
                    <label class="radio-inline">
                    	<input type="radio" name="need_login"  value="0" @if(empty($result) || $result->need_login == 0) checked @endif>&nbsp;&nbsp;不需要用户登录
        			</label>
                </div>
                <div class="clearfix"></div>
            </div>
            <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
            <input type="hidden" name="teachesType" value="0">
            <input type="hidden" name="contentid" value="@if(!empty($result)){{$result->id}}@endif">
            {!! csrf_field() !!}
            <div class="form-inline">
                <div class="form-group">
                  <button type="button" class="btn btn-info" id="publish_save" onclick="saveTeachesData('/admin/teaches/index/course','newsForm',0)">
                    <i class="icon-ok bigger-110"></i>
                    Submit
                  </button>
                </div>
                <div class="form-group col-xs-offset-1">
                  <button type="reset" class="btn">
                    <i class="icon-undo bigger-110"></i>
                    Reset
                  </button>
                </div>
            </div>
        </div>
    </div>
    <div class="content-edit-right">
        <div class="right-drag" id="right-upload-img">
            <div class="upload-img-button">
                <input id="uploadimg" name="uploadimg" type="file" multiple="true">
            </div>
            <div class="can-drag-img">
                    
            </div>
        </div>
    </div>
    <div class="clearfix"></div>
</form>

<script type="text/javascript">
<!--
	$(function(){
		/***图片上传****/
    	$("#uploadimg").uploadify({
    	    'formData'     : {
    	        'fileField':'upfile',
    	        '_token':'{{ csrf_token() }}'
    	    },
    	    "width"           : 120,
    	    "height"          : 30,
    	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
    	    "fileObjName"     : "upfile",
    	    "buttonText"      : "上传图片",
    	    "uploader"        : '/admin/upload/newsimage',
    	    'removeTimeout'	  : 1,
    	    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
    	    'onUploadSuccess':function(file, data, response){
    	    	var data = eval('(' + data + ')');
    	        if (data.status == 'success') {
    	        	var html = '<div class="drag"><img src="'+data.url+'" width="100" /></div>';
    	            $('.can-drag-img').append(html);
    	            xweidrag();    
    	        }else{
    	            alert(data.msg);
    	            return false;
    	        }
    
    	    }
    
    	});
	});
//-->
</script>
@endsection